package com.woniuxy.driverschool.entity;

import java.util.List;

/**
 * 分页类
 * @param <T>
 */
public class PageBean<T> {
    private List<T> beanList;
    private int pageIndex;
    private int pageSize;
    private int totalRecord;
    private int totalPage;
    private int pageBegin;
    private int pageEnd;
    private String url;

    public PageBean() {
        super();
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<T> getBeanList() {
        return beanList;
    }

    public void setBeanList(List<T> beanList) {
        this.beanList = beanList;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRecord() {
        return totalRecord;
    }

    public void setTotalRecord(int totalRecord) {
        this.totalRecord = totalRecord;
    }

    public int getTotalPage() {
        return totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
    }

    public void setTotalpage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageBegin() {
        return pageBegin;
    }

    public void setPageBegin(int pageBegin) {
        this.pageBegin = pageBegin;
    }

    public int getPageEnd() {
        return pageEnd;
    }

    public void setPageEnd(int pageEnd) {
        this.pageEnd = pageEnd;
    }

    @Override
    public String toString() {
        return "PageBean [beanList=" + beanList + ", pageIndex=" + pageIndex + ", pageSize=" + pageSize
                + ", totalRecord=" + totalRecord + ", totalPage=" + totalPage + ", pageBegin=" + pageBegin
                + ", pageEnd=" + pageEnd + ", url=" + url + "]";
    }


    public void setPageBeginAndEnd() {
        if (getTotalPage() < 10) {
            pageBegin = 1;
            pageEnd = getTotalPage();
        } else {
            pageBegin = pageIndex - 5;
            pageEnd = pageIndex + 4;
            if (pageBegin < 1) {
                pageBegin = 1;
                pageEnd = 10;
            }
            if (pageEnd > getTotalPage()) {
                pageBegin = getTotalPage() - 9;
                pageEnd = getTotalPage();
            }
        }
    }
}
